package com.hp.wallet.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hp.wallet.entity.UserWalletRecord;
import com.hp.wallet.service.UserWalletRecordService;
import com.hp.wallet.utils.Result;
import com.hp.wallet.vo.CostVo;
import com.hp.wallet.vo.RefundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("userwalletrecord")
public class UserWalletRecordController {
    @Autowired
    private UserWalletRecordService userWalletRecordService;

    /**
     * 用户消费100元的接口
     *
     */

    @PostMapping("/cost")
    public Result cost(@RequestBody CostVo costVo){
        String info = userWalletRecordService.cost(costVo);

        System.out.println(info);
        if(info.equals("unbalance")){
            return Result.error("余额不足");
        }else {
            return Result.ok();
        }

    }

    /**
     * 用户退款20元接口
     * @param refundVo
     * @return
     */
    @PostMapping("/refund")
    public Result refund(@RequestBody RefundVo refundVo){
        userWalletRecordService.refund(refundVo);
        return Result.ok();
    }


    /**
     * 查询用户钱包金额变动明细的接口
     * @param userId
     * @return
     */
    @RequestMapping("list")
    public Result listbyUserId(@RequestParam("userId") Long userId){
        List<UserWalletRecord> list = userWalletRecordService.list(new QueryWrapper<UserWalletRecord>().eq("user_id", userId));
        return Result.ok().put("list",list);
    }




}
